﻿using System;

namespace Shell.PocoDot.Configurations
{
    /// <summary>
    /// 持久化提供器的扩展类
    /// </summary>
    public static class ProviderConfigurationExtensions
    {
        /// <summary>
        /// 注册一个指定的 PocoDot
        /// </summary>
        /// <typeparam name="TPocoDot">指定的 PocoDot 的类型</typeparam>
        /// <param name="provider">PocoDot 注册处的实例</param>
        /// <returns>PocoDot 注册处的实例</returns>
        public static ProviderConfiguration Register<TPocoDot>(this ProviderConfiguration provider)
            where TPocoDot : PocoDotBase
        {
            PocoDotRegistrar.Registrar.Register<TPocoDot>(provider);
            return provider;
        }

        /// <summary>
        /// 注册两个指定的 PocoDot 的关系
        /// </summary>
        /// <typeparam name="TMainPocoDot">指定的关系中的主 PocoDot 的类型</typeparam>
        /// <typeparam name="TRelatedPocoDot">指定的关系中的从 PocoDot 的类型</typeparam>
        /// <param name="provider">持久化提供器的配置信息</param>
        /// <param name="relationship">主 PocoDot 到从 PocoDot 之间的映射关系</param>
        /// <param name="reversedRelationship">从 PocoDot 到主 PocoDot 之间的映射关系</param>
        /// <returns>持久化提供器的配置信息</returns>
        public static ProviderConfiguration Register<TMainPocoDot, TRelatedPocoDot>(this ProviderConfiguration provider,
           Relationships relationship, Relationships reversedRelationship)
            where TMainPocoDot : PocoDotBase
            where TRelatedPocoDot : PocoDotBase
        {
            RelationRegistrar.Registrar.Register<TMainPocoDot, TRelatedPocoDot>(relationship, reversedRelationship, provider);
            return provider;
        }

        /// <summary>
        /// 注册两个指定的 PocoDot 的关系
        /// </summary>
        /// <param name="provider">持久化提供器的配置信息</param>
        /// <param name="mainPocoDot">指定的关系中的主 PocoDot 的类型</param>
        /// <param name="relationship">主 PocoDot 到从 PocoDot 之间的映射关系</param>
        /// <param name="relatedPocoDot">指定的关系中的从 PocoDot 的类型</param>
        /// <param name="reversedRelationship">从 PocoDot 到主 PocoDot 之间的映射关系</param>
        /// <returns>持久化提供器的配置信息</returns>
        public static ProviderConfiguration Register(this ProviderConfiguration provider,
            Type mainPocoDot, Relationships relationship, Type relatedPocoDot, Relationships reversedRelationship)
        {
            RelationRegistrar.Registrar.Register(mainPocoDot, relationship, relatedPocoDot, reversedRelationship, provider);
            return provider;
        }
    }
}
